package com.cn.auth.model;

import com.cn.auth.vo.SysUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

/**
 * user detail 包装类
 * @author huangzz
 */
public class UserDetailsWrap implements UserDetails, Serializable {
	private SysUser user;

	private ArrayList<GrantedAuthority> authorities;

	public UserDetailsWrap(SysUser user,ArrayList<GrantedAuthority> authorities) {
		this.user = user;
		this.authorities =authorities;
	}

	public UserDetailsWrap() {

	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return this.authorities;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getUserName();
	}


	/**
	 * 该状态应该在IamUserDetailService提前判断和处理
	 * 临时返回true，避免异常发生，
	 *
	 * @return
	 */
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	/**
	 * 该状态应该在IamUserDetailService提前判断和处理
	 * 临时返回true，避免异常发生，
	 *
	 * @return
	 */
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	/**
	 * 该状态应该在IamUserDetailService提前判断和处理
	 * 临时返回true，避免异常发生，
	 *
	 * @return
	 */
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/**
	 * 该状态应该在IamUserDetailService提前判断和处理
	 * 临时返回true，避免异常发生，
	 *
	 * @return
	 */
	@Override
	public boolean isEnabled() {
		return true;
	}

	public SysUser getUser() {
		return user;
	}

	public void setUser(SysUser user) {
		this.user = user;
	}
}
